﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace TM.QWeibo.SDK.Objects
{
    /// <summary>
    /// 用户的信息
    /// </summary>
    [DataContract]
    public class UserInfo : UserInfoBase
    {
        /// <summary>
        /// 头像URL
        /// </summary>
        [DataMember(Name = "head")]
        public string Head { get; set; }
        /// <summary>
        /// 所在地
        /// </summary>
        [DataMember(Name = "location")]
        public string Location { get; set; }
        /// <summary>
        /// 国家码
        /// </summary>
        [DataMember(Name = "country_code")]
        public string CountryCode { get; set; }
        /// <summary>
        /// 省份码
        /// </summary>
        [DataMember(Name = "province_code")]
        public string ProvinceCode { get; set; }
        /// <summary>
        /// 城市码
        /// </summary>
        [DataMember(Name = "city_code")]
        public string CityCode { get; set; }
        /// <summary>
        /// 是否微博认证用户
        /// </summary>
        [DataMember(Name = "isvip")]
        public long IsVip { get; set; }
        /// <summary>
        /// 听众数
        /// </summary>
        [DataMember(Name = "fansnum")]
        public int Fansnum { get; set; }
        /// <summary>
        /// 收听的人数
        /// </summary>
        [DataMember(Name = "idolnum")]
        public int Idolnum { get; set; }

        /// <summary>
        /// 收藏数
        /// </summary>
        [DataMember(Name = "favnum")]
        public int Favnum { get; set; }

        /// <summary>
        /// 是否为accesstoken 用户的听众
        /// </summary>
        [DataMember(Name = "ismyfans")]
        public long IsMyFansFlag { get; set; }

        /// <summary>
        /// 是否为accesstoken用户收听的人
        /// </summary>
        [DataMember(Name = "ismyidol")]
        public long IsMyidolFlag { get; set; }

        /// <summary>
        /// 是否为accesstoken用户收听的人
        /// </summary>
        [DataMember(Name = "isidol")]
        public long IsIdolFlag { get; set; }

        /// <summary>
        /// 是否在当前用户的黑名单中
        /// </summary>
        [DataMember(Name = "ismyblack")]
        public int _IsMyBlack { get; set; }

        /// <summary>
        /// 是否在当前用户的黑名单中
        /// </summary>
        public bool IsMyBlack { 
            get { return _IsMyBlack == 1; }
        }

        /// <summary>
        /// 是否为accesstoken 用户的听众
        /// </summary>
        public bool IsMyFans { 
            get {
               return  IsMyFansFlag > 0;
            } 
        }

        /// <summary>
        /// 是否为accesstoken用户收听的人
        /// </summary>
        public bool IsMyidol
        {
            get
            {
                return IsMyidolFlag > 0;
            }
        }


        /// <summary>
        /// 发表的微博数
        /// </summary>
        [DataMember(Name = "tweetnum")]
        public int Tweetnum { get; set; }

        /// <summary>
        /// 用户最近发的几条微博
        /// </summary>
        [DataMember(Name = "tweet")]
        public List<TweetSummary> Tweet { get; set; }

        /// <summary>
        /// 用户最近发的一条微博
        /// </summary>
        public TweetSummary RecentTweet {
            get {
                return Tweet.FirstOrDefault();
            }
        }

        /// <summary>
        /// 个人标签(key=Id, value=Name)
        /// </summary>
        [DataMember(Name = "tag")]
        public List<UserTag> Tags { get; set; }

        /// <summary>
        /// 个人标签
        /// </summary>
        public string Tag
        {
            get
            {
                if (Tags!=null && Tags.Count > 0)
                {
                    return Tags.Aggregate("", (current, userTag) => current + (userTag.Name + " "));
                }
                return "";
            }
        }

        /// <summary>
        /// 性别
        /// </summary>
        [DataMember(Name = "sex")]
        public Sex SexType { get; set; }

        /// <summary>
        /// 性别
        /// </summary>
        public string Sex
        {
            get
            {
                switch (SexType.GetHashCode())
                {
                    case 1: return "男";
                    case 2: return "女";
                    default: return "未知";
                }
            }
        }

        /// <summary>
        /// 个人描述
        /// </summary>
        [DataMember(Name = "introduction")]
        public string Introduction { get; set; }

        /// <summary>
        /// 认证信息
        /// </summary>
        [DataMember(Name = "verifyinfo")]
        public string VerifyInfo { get; set; }

    }
    /// <summary>
    /// 用户标签
    /// </summary>
    [DataContract]
    public class UserTag
    {
        [DataMember(Name = "id")]
        public string Id { get; set; }
        [DataMember(Name = "name")]
        public string Name { get; set; }
    }
}
